package com.woniu.user.commons;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.woniu.user.exception.WebException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.PrintWriter;

// 全局异常处理
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(WebException.class)
    public Result<Object> handleWebException(WebException e){
        e.printStackTrace();// 打印堆栈信息
        return Result.fail(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result<Object> handleException(Exception e){
        e.printStackTrace();
        return Result.fail(500, "服务器繁忙");
    }

}
